<?php

namespace app\common\model;

use think\Model;

/**
 * em_admin
 * @property integer $id (主键)
 * @property integer $role_id 角色ID
 * @property string $username 账号
 * @property string $password 密码
 * @property string $nickname 昵称
 * @property integer $status 状态 0禁用 1正常
 * @property string $avatar 头像
 * @property string $mobile 手机号码
 * @property string $token 用户TOKEN
 * @property string $last_login_ip 最后登录IP
 * @property string $last_login_time 最后登录时间
 * @property string $create_time
 * @property string $update_time
 */
class Admin extends Model
{
    /**
     * The connection name for the model.
     *
     * @var string|null
     */
    protected $connection = 'mysql';

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'em_admin';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $pk = 'id';


    public static function getProfile()
    {
        $token = request()->header('XX-TOKEN', '');
        return self::where('token', $token)->find();
    }

    public function role()
    {
        return $this->belongsTo('Role', 'role_id')->bind(['role_name' => 'name']);
    }

}
